<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
	
//get variables passed in
$timeslot_id = mysql_real_escape_string(strip_tags($_POST['id']));
$building_id = mysql_real_escape_string(strip_tags($_POST['bid']));
$hours_per_week = mysql_real_escape_string(strip_tags($_POST['hpw']));
$starttime = mysql_real_escape_string(strip_tags($_POST['start']));
$endtime = mysql_real_escape_string(strip_tags($_POST['end']));

$get_building_data = mysql_query("SELECT * FROM buildings WHERE id = $building_id");
$building_name = mysql_result($get_building_data,0,'building_name');
$abbreviation = mysql_result($get_building_data,0,'abbreviation');


if (isset($_POST['mon']))
{
	$mon = $_POST['mon'];
}
else
{
	$mon = 0;
}

if (isset($_POST['tues']))
{
	$tues = $_POST['tues'];
}
else
{
	$tues = 0;
}

if (isset($_POST['weds']))
{
	$weds = $_POST['weds'];
}
else
{
	$weds = 0;
}

if (isset($_POST['thurs']))
{
	$thurs = $_POST['thurs'];
}
else
{
	$thurs = 0;
}

if (isset($_POST['fri']))
{
	$fri = $_POST['fri'];
}
else
{
	$fri = 0;
}

if (isset($_POST['sat']))
{
	$sat = $_POST['sat'];
}
else
{
	$sat = 0;
}

if (isset($_POST['sun']))
{
	$sun = $_POST['sun'];
}
else
{
	$sun = 0;
}

echo "<h1>Edit Timeslot in $building_name</h1>";

//select statement
$query="UPDATE time_slots 
SET hours_per_week='$hours_per_week', start_time='$starttime', end_time='$endtime',
Monday='$mon', Tuesday='$tues', Wednesday='$weds', Thursday='$thurs', Friday='$fri', Saturday='$sat', Sunday='$sun'
WHERE id='$timeslot_id'";

$result=mysql_query($query);

//close
mysql_close();

if ($result)
{
	echo "Timeslot has been successfully updated!";
	echo "<br />";
}
else
{
	echo "Timeslot was NOT able to be updated at this time!";
	echo "<br />";
}

echo "<p>";
	echo "<a href='timeslots.php?id=$building_id'>&lt;&lt; Back to Timeslots Portal</a><br />";
echo "</p>";
?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>